import requests
import json

if __name__ == "__main__":
    #获取企业ID
    headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
               'referer':'https://music.163.com/song?id=1859652717'}
    id_list = []
    all_data_list = [] 
    url='http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsList'
    for page in range(1,6):
        page=str(page)
        data={
            'on': 'true',
            'page': page,
            'pageSize': '15',
            'productName': '',
            'conditionType': '1',
            'applyname': '',
            'applysn': ''
            }
        json_ids = requests.post(url=url,headers=headers,data=data).json()
        for dic in json_ids['list']:
            id_list.append(dic['ID'])

    post_url='http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsById'
    for id in id_list:
        data={"id":id}
        detail_json = requests.post(url=post_url,headers=headers,data=data).json()
        all_data_list.append(detail_json)

    with open("List.txt",'w',encoding='utf-8') as file:
        for each in all_data_list:
            file.write("公司名称："+each['epsName']+'\n')
            file.write("公司代表："+each['businessPerson']+'\n')
            file.write("经营范围："+each['certStr']+'\n')
            file.write("----------------------------------------------------------\n")
            
    print("over")
        
